package com.xzkydz.all_sensor.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.xzkydz.all_sensor.activity.MainActivity;
import com.xzkydz.all_sensor.allsensor.R;

/**
 * Created by Smilekun on 2016/8/22.
 */
public class TimeFragment extends Fragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View  view  =  inflater.inflate(R.layout.fragment_time, container, false);
        final MainActivity mActivity  = (MainActivity)getActivity();
        Button  mButton  =  (Button)view.findViewById(R.id.btn_time);
        ToggleButton toggleButton  = (ToggleButton)view.findViewById(R.id.tbn_fuhao);

        toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    mActivity.fuhaoString ="+";
                    Toast.makeText(mActivity,mActivity.fuhaoString,Toast.LENGTH_SHORT).show();
                }else {
                    mActivity.fuhaoString ="—";
                    Toast.makeText(mActivity,mActivity.fuhaoString,Toast.LENGTH_SHORT).show();
                }
            }
        });

        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String completeData ="4B5908010500015100040159";
                mActivity.sendPortData(completeData);  //发送数据
                Toast.makeText(mActivity,"开始...",Toast.LENGTH_SHORT).show();
            }
        });
        return   view ;
    }
}
